package com.me.util;

import java.util.Random;

public class Security {

	/**
	 * 
	 * @param text
	 *            加密
	 * @return
	 */

	public static String addSecurity(String text) {
		if(text == null) return null;
		try {
			byte[] _ssoToken = text.getBytes("UTF-8");
			int num = new Random().nextInt(50);
			String name = num+"<";
			// char[] _ssoToken = ssoToken.toCharArray();
			for (int i = 0; i < _ssoToken.length; i++) {
				int asc = _ssoToken[i] + num;
				name = name + asc + "<";
			}
			return name;
		} catch (Exception e) {
			return null;
		}

	}

	private static int addSecurity(int number) {
		return number >> 2;
	}

	/**
	 * 
	 * @param text
	 *            解密
	 * @return
	 */

	public static String removeSecurity(String text) {
		if (text == null) {
			return null;
		}

		try {
			String texts[] = text.split("<");
			int num = Integer.parseInt(texts[0]);
			byte b[] = new byte[texts.length-1];
			for (int i = 0; i < texts.length-1; i++) {
				b[i] = (byte) (Integer.parseInt(texts[i+1]) - num);
			}
			String r = new String(b,"UTF-8");
			return r;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}

	}

	private static int removeSecurity(int num) {
		return num << 2;
	}
	
}
